<?php
/* Libraries */
include_once("dbConn.php");	

/* preProcessor */
session_start();

/* Guest Login */
if ($_GET['guestLogin'])
{
	$_SESSION['user_id'] = 3;
}

/* Global Variables */
$userID = $_SESSION['user_id'];	

if (!isset($_SESSION['user_id']))
{
/*
//logIn Page
*/
	include_once('login/login.class.php');
	
	if ($_SERVER['HTTPS'] == "on")
	{
		$checked = 'checked="checked"';
		$sessionText = "Session Secured";
	}
	else
	{
		$sessionText = "Secure Session";
	}


//Choose Wallpaper
	$noWalls = 0;
	$randNo = 0;
	$wallPath = "Images/Wallpapers/Login/";
	$Wallpapers = array("");
	if (file_exists($wallPath))
	{
		if ($dirListing = opendir($wallPath))
		{
			while (($wallFile = readdir($dirListing)) !== false)
			{
		        if ($wallFile != "." && $wallFile != ".." && is_file($wallPath . "/" . $wallFile))
				{
					array_push($Wallpapers, $wallFile);
					$noWalls++;
		        }
			}
			$randNo = rand(1, $noWalls);
			$Walls = array_values($Wallpapers);
			$randWall = $Walls[$randNo];
		}
	}

?>
<script type="text/javascript">
	var pageStartTime;
	var httpGenTime <?	if (isset($_POST['httpGenTime']))
						{
							echo "= " . $_POST['httpGenTime'];
						} ?>;
	{
		pageStartTime = new Date().getTime();
	}
</script>
<html>
<head>
<title>xNET OS - Login</title>
<meta name="robots" content="noindex,nofollow" />
<link href="Style/xNet.css" rel="stylesheet" type="text/css" />
<link href="login/css/login.css" rel="stylesheet" type="text/css" media="all" />
<script language="javascript" type="text/javascript" src="login/js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="Scripts/uiCore.js"></script>
<script language="javascript" type="text/javascript" src="login/js/form.js"></script>
<script language="javascript" type="text/javascript" src="login/js/login.js"></script>
<script type="text/javascript">

var desUI;

function startUp()
{
	$("#wait").fadeOut(1, function() {
    	$("#logInSheet").fadeOut(1000);	
	});
	var pageEndTime = new Date().getTime();
	var timeDiff = pageEndTime - pageStartTime;
	document.getElementById("httpGenTime").value = timeDiff;
	if (httpGenTime != null)
	{
		var perfLoss = 1 - (httpGenTime / timeDiff);
		perfLoss *= 100;
		perfLoss = Math.round(perfLoss, 4);
		if (perfLoss > 0)
		{
			document.getElementById("perfLoss").innerHTML = "Estimated Performance Loss: " + perfLoss + "%";
		}
		else
		{
			document.getElementById("perfLoss").innerHTML = "No Inital Performance Loss Detected";
		}
	}
}

function setUI(uiPath)
{
	desUI = uiPath;
}

function showGuestLogin()
{
	$("#guestLogin").fadeOut(1, function() {
		$("#guestLogin").removeClass("Invisible");
		$("#guestLogin").fadeIn(1000);
	});
}

function guestLogin()
{
	location.href = "?guestLogin=1&desUI=" + desUI;
}

function logIn()
{
	$("#wrapper").animate({height: 0, opacity: 0}, 525);
	$("#wait").fadeIn(263);
	//setTimeout("showCancelLogin();", 7500);
}

function cancelLogin()
{
	$("#btnCancel").remove();
	showLogin();
}

function showCancelLogin()
{
	if (waitScreenShown)
	{
		var cancelBtn = '<div id="cancelLogin"><br /><input type="button" id="btnCancel" onclick="cancelLogin()" value="Cancel" class="buttonfield Invisible" /></div>';
		$("#wait").append(cancelBtn);
		$("#wait").fadeOut(1, function() {
			$("#wait").removeClass("Invisible");
			$("#wait").fadeIn(750);
		});
	}
}

function enterOS()
{
	$("#logInSheet").fadeIn(1000, function() {
			location.href = "index.php";
	});
}

function toggleSecurity(secure)
{
	document.getElementById("submit").disabled = true;
	$("#logInSheet").fadeIn(1000, function() {
		if (secure)
		{
			document.getElementById("formSec").submit();
		}
		else
		{
			location.href = "http://xnetos.ravex.net.au"
		}
	});
	return false;
}

function showLogin()
{
	$("#wait").fadeOut(300, function() {
		$("#wait").remove("#cancelLogin");
	});
	$("#wrapper").animate({height: 175, opacity: 1}, 600);
}

function showUserPage()
{
	$("#wait").fadeOut(300);
	$("#wrapper").animate({height: 215, opacity: 1}, 600);
}


</script>
</script>
<style type="text/css">
* {
	font-size:1em;
}
html, body {
	height:100%;
}
html {
 background-image:url(Images/Wallpapers/Login/<? echo $randWall ?>);
	background-position:center;
	background-repeat:repeat;
}
#loginContents {
	background-image:url(Images/loginBG.png);
	background-repeat:repeat;
}
#logInSheet {
	background-color:#272727;
	position:absolute;
	top:0px;
	left:0px;
	width:100%;
	height:100%;
	z-index:1000;
}
#wait {
	z-index:5;
	position:relative;
	text-align:center;
	padding-bottom:50px;
}
</style>
</head>
<body onLoad="startUp();">
<div id="logInSheet" class="OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/Logo.png" alt="xNET OS" class="LogoWashed" style="padding-bottom:6px;" /> <br />
        <br />
        <img src="Images/ajaxLoader.gif" alt="Loading..." /> </td>
    </tr>
  </table>
</div>
<div id="guestLogin" class="OSTask Invisible">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/winOverflow.png" alt="Window Overflow" /> <br />
        <br />
        Choose A User Interface<br />
        <br />        
        <?
			$uiQuery = mysql_query("SELECT * FROM userInterfaces");
			while($uiList = mysql_fetch_array($uiQuery))
			{
				echo '<label for="uiD'.$uiList["ID"].'"><input name="uiD" onclick="setUI(\''.$uiList["dirName"].'\')" id="uiD'.$uiList["ID"].'" type="radio" value="'.$uiList["dirName"].'" />'.$uiList["uiName"].'</label><br />';
			}
		?>
        <input type="button" value="Login" onClick="guestLogin()" /></td>
    </tr>
  </table>
<? ?>
</div>
<div id="err"></div>
<img src="Images/Logo.png" /><br>
<br>
<br>
<br>
<div id="loginPane">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center"><table class="appWindow" style="position:relative;" cellspacing="0" cellpadding="0">
          <tr>
            <td id="topLeft"/>
            <td id="topMiddleLeft"/>
            <td align="center" id="topMiddleCentre"><table cellspacing="0" cellpadding="0">
                <tr>
                  <td class="winTitleL"/>
                  <td id="winTitle" style="font-size:1.0em;">xNet OS Login</td>
                  <td class="winTitleR"/>
                </tr>
              </table></td>
            <td id="topMiddleRight"/>
            <td id="topRight"/>
          </tr>
          <tr>
            <td id="midLeft"/>
            <td id="loginContents" height="100%" colspan="3"><div id="wrapper"></div>
              <div id="wait"><img src="Images/ajaxLoader.gif" alt="Loading..." /></div></td>
            <td id="midRight"/>
          </tr>
          <tr/>
          <tr>
            <td id="btmLeft"/>
            <td id="btmMiddleLeft"/>
            <td align="center" id="btmMiddleCentre">Rave X Digital&reg;</td>
            <td id="btmMiddleRight"/>
            <td id="btmRight"/>
          </tr>
        </table></td>
    </tr>
  </table>
</div>
<form id="formSec" name="formSec" action="https://secure231.websitewelcome.com/~ravex/xnet_os/" method="post">
  <input type="hidden" id="httpGenTime" name="httpGenTime" value="0" />
</form>
<? }

else {
/*
// xNet OS Environment
*/
	$nameQuery = mysql_query("SELECT firstname, lastname FROM users WHERE id = '$userID'");
	$name = mysql_result($nameQuery,0,0) . "&nbsp;" . mysql_result($nameQuery,0,1);

	if (isset($_GET['desUI']))
	{
		$uiPath = "UI/".$_GET['desUI']."/index.php";
	}
	else
	{
		$chosenUI = mysql_result(mysql_query("SELECT UI FROM users WHERE ID = '$userID'"),0,0);
		$desUI = mysql_result(mysql_query("SELECT dirName FROM userInterfaces WHERE ID = '$chosenUI'"),0,0);
		$uiPath = "UI/$desUI/index.php";
	}
//Choose Wallpaper
	$noWalls = 0;
	$randNo = 0;
	$wallPath = "Images/Wallpapers/Env";
	$Wallpapers = array("");
	if (file_exists($wallPath))
	{
		if ($dirListing = opendir($wallPath))
		{
			while (($wallFile = readdir($dirListing)) !== false)
			{
		        if ($wallFile != "." && $wallFile != ".." && is_file($wallPath . "/" . $wallFile))
				{
					array_push($Wallpapers, $wallFile);
					$noWalls++;
		        }
			}
			$randNo = rand(1, $noWalls);
			$Walls = array_values($Wallpapers);
			$randWall = $Walls[$randNo];
		}
	}
?>
<html>
<head>
<title>xNet OS</title>
<script src="Scripts/jQuery.js" type="text/javascript"></script>
<script src="Scripts/uiCore.js" type="text/javascript"></script>
<script src="Scripts/uiDrag.js" type="text/javascript"></script>
<script src="Scripts/uiResize.js" type="text/javascript"></script>
<script src="Scripts/uiEffects.js" type="text/javascript"></script>
<script src="Scripts/uiEffects_Transfer.js" type="text/javascript"></script>
<script src="Scripts/noTextSel.js" type="text/javascript"></script>
<script src="Scripts/noTextSelPk.js" type="text/javascript"></script>
<script src="Scripts/hotKeys.js" type="text/javascript"></script>
<script src="Scripts/xNET.js" type="text/javascript"></script>
<link href="Style/xNet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
html, body {
	margin:0px;
	padding:0px;
	border:0px;
	height:100%;
	background-color:#272727;
	font-family:Tahoma;
	font-size:0.85em;
	overflow:hidden;
}
body {
 background-image: url(Images/Wallpapers/Env/<? echo $randWall ?>);
	background-position: center;
	background-repeat: no-repeat;
}
.ui-effects-transfer {
	border-color:#DEDEDE;
	border-style:solid;
	border-width:1px;
	filter:alpha(opacity=45);
	-moz-opacity:0.45;
	-khtml-opacity: 0.45;
	opacity: 0.45;
}
</style>
<!--[if ie]>
    <style>
        .appWindow #topMiddleCentre
        {
            width:80%;
        }
    </style>
<[end if]-->
<script type="text/javascript">
{
	showTrace = false;
}
</script>
</head>
<body onLoad="startUp()">
<!--OS Tasks-->
<div id="startLoader" class="OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/Logo.png" alt="xNET OS" class="LogoWashed" /> <br />
        <br />
        <img src="Images/ajaxLoader.gif" alt="Loading..." /> </td>
    </tr>
  </table>
</div>
<div id="taskManager" class="Invisible OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/Icons/TaskMan_x256.png" alt="xNET OS" /> <br />
        <br />
        <br />
        Need To Create JS Based Task Manager<br>
        For Killing Misbehaving Windows </td>
    </tr>
  </table>
</div>
<div id="maxWins" class="Invisible OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/winOverflow.png" alt="Window Overflow" /> <br />
        <br />
        Maximum Window Limit Reached<br />
        <br />
        <span style="font-size:small; font-weight:normal;">Please Close An Existing Window &amp; Re-Launch Application</span><br />
        <br />
        <input type="button" value="Cancel" onClick="hideOSTask()" /></td>
    </tr>
  </table>
</div>
<div id="logOut" class="Invisible OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><span id="logOutSpan"><img src="Images/logOut.png"> </span><br />
       Logout User Session<br />
        <br />
        <span style="font-size:small; font-weight:normal;">Ends User Session &amp; Closes all Windows</span><br />
        <br />
        <input type="button" value="Logout" onClick="logOut();">
        &nbsp;|&nbsp;
        <input type="button" value="Cancel" onClick="hideOSTask('logOut');"></td>
    </tr>
  </table>
</div>
<div id="refreshEnvironment" class="Invisible OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/Desktop.png"><br />
        Refresh Environment<br />
        <br />
        <span style="font-size:small; font-weight:normal;">Refreshes Your Current Environment<br />
        All Windows &amp; Unsaved Documents will be Lost</span> <br />
        <br />
        <input type="button" value="Refresh" onClick="refreshEnvironment();">
        &nbsp;|&nbsp;
        <input type="button" value="Cancel" onClick="hideOSTask();"></td>
    </tr>
  </table>
</div>
<div id="closeAllWins" class="Invisible OSTask">
  <table cellpadding="0" cellspacing="0" class="Fill">
    <tr>
      <td class="Fill" style="text-align: center;"><img src="Images/closeWins.png" /> <br /><br />
       Close All Windows<br />
        <br />
        <span style="font-size:small; font-weight:normal;">Closes all Active Windows</span><br />
        <br />
        <input type="button" value="Confirm" onClick="closeAllWins();">
        &nbsp;|&nbsp;
        <input type="button" value="Cancel" onClick="hideOSTask();"></td>
    </tr>
  </table>
</div>
<!--/OS Tasks-->
<div id="OSTask"></div>
<!-- User Interface -->
<?
	if(file_exists($uiPath))
	{
		include("UI/$desUI/index.php");
	}
	else
	{
		echo "UI File Cannot Be Found";
	}
} 
//mysql_close($link);
?>
</body>
</html>
